package com.qsh.ts.mem;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by sehuaqi on 2017/6/22.
 */
@Service
public class MemDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public Map<String,Object> getUser(int id){
        Map<String,Object> map = null;

        String sql = "select * from mem_user where id = ? limit 1";
        map = jdbcTemplate.queryForMap(sql,id);

        return map;
    }

    public List getTimer(int id){

        String sql = "select * from timer order by id DESC ";

        List list = jdbcTemplate.queryForList(sql);

        return list;
    }

    public int addTimer(String t, String c) {

        String insertSql = "INSERT INTO timer ( t, c) VALUES ('"+t+"', '"+c+"')";
        jdbcTemplate.execute(insertSql);

        return 1;
    }
}
